#include <cmath>
#include <iostream>
#include <string>

bool f(int x) {
    for (int i = 2; i <= static_cast<int>(std::sqrt(x)) + 1; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);

    std::string c = "";
    int wrong = 0;
    for (const auto& word : split(input, ' ')) {
        if (word == "zero") {
            c += '0';
        } else if (word == "one") {
            c += '1';
        } else if (word == "two") {
            c += '2';
        } else if (word == "three") {
            c += '3';
        } else if (word == "four") {
            c += '4';
        } else if (word == "five") {
            c += '5';
        } else if (word == "six") {
            c += '6';
        } else if (word == "seven") {
            c += '7';
        } else if (word == "eight") {
            c += '8';
        } else if (word == "nine") {
            c += '9';
        } else {
            wrong = 1;
            break;
        }
    }

    if (wrong == 1 || c.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        int num = std::stoi(c);

        int nmin = 0;
        int nmax = 0;

        for (int i = num + 1; i < 1000; i++) {
            if (f(i)) {
                nmax = i;
                break;
            }
        }

        for (int i = num - 1; i > 99; i--) {
            if (f(i)) {
                nmin = i;
                break;
            }
        }

        if (num - nmin > nmax - num) {
            std::cout << nmax << std::endl;
        } else {
            std::cout << nmin << std::endl;
        }
    }

    return 0;
}